package br.unicamp.integralization.dto;

import java.util.List;
import java.util.regex.Pattern;

public class Subject implements Comparable<Subject>{

	private String abbreviation;
	private int credits;
	private int groupMatches;
	
	

	public Subject() {
	}

	public Subject(String abbreviation, int credits) {
		this.abbreviation = abbreviation;
		this.credits = credits;
		this.groupMatches=0;
	}

	public int getGroupMatches() {
		return groupMatches;
	}
	
	public void setGroupMatches(int groupMatches) {
		this.groupMatches = groupMatches;
	}
	
	public String getAbbreviation() {
		return abbreviation;
	}

	public void setAbbreviation(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public int getCredits() {
		return credits;
	}

	public void setCredits(int credits) {
		this.credits = credits;
	}

	public boolean matches(Subject subject) {
		return Pattern.matches(getAbbreviation().replace('-', '.'), subject.getAbbreviation());
	}
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof Subject){
			return matches((Subject)o);
		}
		return false;
	}
	
	@Override
	public String toString(){
		return getAbbreviation() +String.format("(%d)", credits);
	}

	@Override
	public int compareTo(Subject another) {
		return this.groupMatches-another.groupMatches;
	}

	public void updateMatchingGroups(List<SubjectGroup> electiveGroups) {
		for (SubjectGroup subjectGroup : electiveGroups) {
			if(subjectGroup.matches(this)){
				groupMatches++;
			}
		}
		
	}
	
	
}
